<?php
/**
 * 后台广告管理API
 */

namespace App\Http\Controllers\CmsApi;


use App\Http\Controllers\BaseController;
use App\Http\Services\AdServices;
use App\Http\Services\MsgServices;
use Illuminate\Http\Request;
use App\Lib\Response;
use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use Illuminate\Support\Facades\Redis;


class AdAPIController extends BaseController
{
    protected $requestInstance;// 请求类实例
    protected $adServices;// 广告Services
    protected $serviceMsg;

    public function __construct()
    {
        $this->requestInstance = new Request();
        $this->adServices = new AdServices();
        $this->serviceMsg = new MsgServices();

    }

    /**
     * 后台管理
     * 广告创建
     * @author 
     * */
    public function adCreate()
    {
        do {
            if (!$this->checkRequest(false)) {
                break;
            }
            $adServer = new AdServices();
            $adServer->requestData = $this->requestData;
            $res = $adServer->adCreate();
            $this->responseData = $res;
            if($res['code'] ==0 && !empty($res['data']['params'])){
                $this->serviceMsg->sendAdChangeMsg($this->requestData['type'],$res['data']['params']);
            }
        } while (false);

        $this->responseData();
    }

    /**
     * 后台接口
     * 广告更新
     * @author  
     * */
    public function adUpdate()
    {
        do {
            if (!$this->checkRequest(false)) {
                break;
            }
            $adServer = new AdServices();
            $adServer->requestData = $this->requestData;
            $res = $adServer->adUpdate();
            $this->responseData = $res;
            if($res['code'] ==0 && isset($res['data']['params'])){
                $this->serviceMsg->sendAdChangeMsg($this->requestData['type'],empty($res['data']['params']) ? [] : $res['data']['params']);
            }

        } while (false);

        $this->responseData();
    }

    /**
     * 后台接口
     * 广告删除
     * @author  
     * */
    public function adRemove()
    {
        do {
            if (!$this->checkRequest(false)) {
                break;
            }
            $adServer = new AdServices();
            $adServer->requestData = $this->requestData;
            $res = $adServer->adRemove();
            $this->responseData = $res;
            if($res['code'] ==0 && !empty($res['data']['type'])){
                $this->serviceMsg->sendAdChangeMsg($res['data']['type'] ,empty($res['data']['params']) ? [] : $res['data']['params']);
            }
        } while (false);

        $this->responseData();
    }

}